{include file="common/head"/}
<style type="text/css">
.layui-table-view{ margin: 0px!important; }
</style>
<div class="main">
    <div class="layui-card-header">收款账号管理</div> 
    <div class="pd15"> <table class="layui-table layui-hide" id="banklist" lay-filter="listss"></table></div>
    <div class="pd15">
        <div class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe702;</i>请勿同时启动多个账号</div>
        <button type="button" class="layui-btn layui-btn-sm" lay-filter="addbank" lay-submit><i class="layui-icon">&#xe654;</i>新增收款账号</button>
    </div>
</div> 
<script type="text/html" id="open">
    <input type="checkbox" name="open" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.open == 1 ? 'checked' : '' }}>
</script> 
<script type="text/html" id="qrcodepic">
    {{# if(d.qrcode){ }}<img src="{{d.qrcode}}" style=" height:28px;" onmouseover="layer.tips('<img src={{d.qrcode}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">{{# } }}
</script> 
<script type="text/html" id="action"> 
    <button type="button" class="layui-btn layui-btn-xs" lay-event="editbank" lay-submit>编辑</button> 
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="/static/plugins/layui/layui.js"></script> 
<script>
    layui.use(['layer','table','form'], function() {
        var table = layui.table,form = layui.form, $ = layui.jquery, layer = layui.layer;
        var tableIn = table.render({
            id: 'listss',
            elem: '#banklist', 
            url: '{:url("bank")}',
            method: 'post', 
            page: true,
            cols: [[  
                {field: 'name', title: '账号类型',align: 'center', width:138},
                {field: 'bank_no', title: '收款账号',align: 'center', width: 200}, 
                {field: 'bank_name', title: '账号名称',align: 'center', width: 138}, 
                {field: 'qrcode', title: '收款二维码',align: 'center', width:100,templet: '#qrcodepic'}, 
                {field: 'open', title: '状态',align: 'center', width: 130, toolbar: '#open'},
                {field: 'addtime', title: '添加时间',align: 'center', width: 143},
                {field: 'content', title: '备注',align: 'center'},
                {width: 160, align: 'center', toolbar: '#action'}
            ]],
            limit: 10 //每页默认显示的数量
        }); 
        form.on('switch(open)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var open = obj.elem.checked===true?1:0;
            $.post('{:url("editState")}',{'id':id,'open':open},function (res) {
                layer.close(loading);
                if (res.status==1) {
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        tableIn.reload();
                    }); 
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
        table.on('tool(listss)', function(obj) {
            var data = obj.data;
            if (obj.event === 'del'){
                layer.confirm('该收款账号吗', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            if (obj.event === 'editbank'){
                layer.open({
                    type: 2,
                    title:'修改账号', 
                    closeBtn:1,
                    shadeClose: true,
                    scrollbar: false,
                    anim: 2,
                    area: ['100%', '478px'], 
                    content:"{:url('user/financial/editbank')}?id=" +data.id
                }); 
            }
        });
        form.on('submit(addbank)', function (data) {
            layer.open({
                type: 2,
                title:'添加账号', 
                closeBtn:1,
                shadeClose: true,
                scrollbar: false,
                anim: 2,
                area: ['100%', '478px'], 
                content:"{:url('user/financial/addbank')}" 
            }); 
        }); 
    });
</script>
</body>
</html>